

-- Namespace
	local _,mod = ...


-- Locals
	local scale = .8
	
	local font = {mod.path..'media\\tempesta.ttf',16,'OUTLINEMONOCHROME'}
	
	local c_border = {.07,.07,.07}


-- Time
	local timeblock = mod:CreateFrame('Frame',nil,UIParent)
		timeblock:SetPoint('BOTTOMRIGHT',-24,4)
		timeblock:EnableMouse(true)
		mod.timeblock = timeblock
		
		timeblock:SetScript('OnMouseUp',ToggleCalendar)
		
		timeblock:SetScript('OnEnter',function(self)
			local hr,mn = GetGameTime()
			local meri = 'AM'
			if hr >= 12 then
				hr = hr - 11
				meri = 'PM'
			end
			if hr == 0 then
				hr = 12
			end
			GameTooltip:SetOwner(self,'ANCHOR_CURSOR')
			GameTooltip:AddDoubleLine(
				('|cffffffffLocal: %s\nServer: %s:%02d %s|r'):format(
					date('Local: %#I:%M %p'),hr,mn,meri
				),
				date('|cffffffff%a, %x\n |r')
			)
			GameTooltip:Show()
		end)
		timeblock:SetScript('OnLeave',function()
			GameTooltip:Hide()
		end)
	
	local ttext = timeblock:CreateFontString(nil,'OVERLAY')
		ttext:SetPoint('BOTTOMRIGHT')
		ttext:SetFont(unpack(font))
		ttext:SetJustifyH('RIGHT')
		timeblock.text = ttext
	
	mod:timer_register(10,true,function()
		ttext:SetText(date('%#I:%M'))
		timeblock:SetHeight(ttext:GetHeight())
		timeblock:SetWidth(ttext:GetWidth())
	end)()


-- Mail
	local mailblock = mod:CreateFrame('Frame',nil,UIParent)
		mailblock:SetHeight(16) mailblock:SetWidth(16)
		mailblock:SetPoint('BOTTOMRIGHT',-(24+74),4)
		mailblock:EnableMouse(true)
		mailblock:Hide()
		mod.mailblock = mailblock
		
		mailblock:SetScript('OnEnter',function(self)
			local s1,s2,s3 = GetLatestThreeSenders()
			local text = (s1 or s2 or s3) and HAVE_MAIL_FROM or HAVE_MAIL
			if s1 then
				text = text..'\n\194\183 '..s1
			end
			if s2 then
				text = text..'\n\194\183 '..s2
			end
			if s3 then
				text = text..'\n\194\183 '..s3
			end
			GameTooltip:SetOwner(self,'ANCHOR_CURSOR')
			GameTooltip:SetText(text)
			GameTooltip:Show()
		end)
		mailblock:SetScript('OnLeave',function()
			GameTooltip:Hide()
		end)
	
	local micon = mailblock:CreateTexture(nil,'OVERLAY')
		micon:SetAllPoints(true)
		micon:SetTexture(mod.path..'media\\mail.tga')
		mailblock.icon = micon
	
	local function CHECKMAIL()
		if HasNewMail() == 1 then
			mailblock:Show()
		else
			mailblock:Hide()
		end
	end
	
	mod:event_register('UPDATE_PENDING_MAIL',CHECKMAIL)
	mod:event_register('PLAYER_ENTERING_WORLD',CHECKMAIL)


-- Queues
	local queueblock = mod:CreateFrame('Frame',nil,UIParent)
		queueblock:SetHeight(16) queueblock:SetWidth(16)
		queueblock:SetPoint('BOTTOMRIGHT',-(24+104),4)
		queueblock:EnableMouse(true)
		queueblock:Hide()
		mod.queueblock = queueblock
	
	local qicon = queueblock:CreateTexture(nil,'OVERLAY')
		qicon:SetAllPoints(true)
		qicon:SetTexture(mod.path..'media\\queues.tga')
		queueblock.icon = qicon
	
	QueueStatusMinimapButton:SetHeight(0)
	QueueStatusMinimapButton:SetWidth(0)
	QueueStatusMinimapButton:ClearAllPoints()
	QueueStatusMinimapButton:SetAllPoints(queueblock)
	QueueStatusMinimapButton:DisableDrawLayer('OVERLAY')
	QueueStatusMinimapButtonIcon:Hide()
	QueueStatusMinimapButton:HookScript('OnShow',function()
		queueblock:Show()
	end)
	QueueStatusMinimapButton:HookScript('OnHide',function()
		queueblock:Hide()
	end)
	QueueStatusFrame:SetClampedToScreen(true)
